using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Input.Touch;


namespace TrovaIntruso.core
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Button : Microsoft.Xna.Framework.DrawableGameComponent
    {
        public delegate void ClickDelegate();
        ClickDelegate click = null;

        private Sprite texture;

        public Button(Game game,Sprite tex)
            : base(game)
        {
            texture = tex;
            // TODO: Construct any child components here
        }
      

        public void BindClick(ClickDelegate c) {
            click = c;
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            if (StaticOperation.GestureReady && Enabled)
            {
                GestureSample gs = StaticOperation.LastGesture;
                if (gs.GestureType == GestureType.Tap && click != null && texture.Contains(gs.Position))
                {
                    StaticOperation.PlayEffect("click");
                    click();
                }
            }
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            if(StaticOperation.Batch!=null && Visible)
                texture.Draw(StaticOperation.Batch);
            base.Draw(gameTime);
        }



    }
}
